<?php

class Application_Model_Mail extends Sgit_Model
{  
    
    protected $_name = 'mail';
    protected $_primary = 'id';

    function getMails($values){
        
      
        
        $select=$this->getAdapter()
            ->select()
            ->from(array($this->_name))
            ->joinLeft('mail2user', "mail2user.id_mail = {$this->_name}.id", array('id_para','leido','f_leido'=>'updated_on'))
            ->order('created_on desc')  ;
            
            
        if($values['id_user'])
           $select->where('id_para=?',$values['id_user']);
        if($values['limit'])
           $select->limit($values['limit'],$values['offset'] ? $values['offset'] :0);
        if($values['leido'])
           $select->where('leido=?',$values['leido']);    


        $rows = $this->getAdapter()->fetchAll($select);
     

        return $rows;
    }


}


    

